#!/bin/bash
# Date  : 2021-01-15 20:07:09
# Author: scg
# Email : uzz_scg@163.com
# Func  : 批量登陆Linux主机并执行命令
username="root"
password="bit123"
port="22"
timeout=3
#所有集群的Masters安装nfs-kernel-server
#cmd0="apt update && apt install nfs-kernel-server && mkdir /nfsdata && chmod 666 /nfsdata && touch /etc/exports && test -s /etc/exports && sed -i '$a /nfsdata *(rw,sync,no_subtree_check,no_root_squash)' /etc/exports || echo '/nfsdata *(rw,sync,no_subtree_check,no_root_squash)' >> /etc/exports && cd /root && exportfs -rv && systemctl restart rpcbind && systemctl restart nfs-kernel-server && showmount -e"

login(){
    echo ""
    echo "-------------------------------------------------------- "
    echo "username: $username  password: $password  port: $port  timeout=$timeout"
    echo "command: $cmd"
    echo "Remote exec command script"
    echo "--------------------------------------------------------"
    echo ""
cmd0="rm -rf /etc/etcd/ssl && mkdir -p /etc/etcd/ssl"
    for ip in `cat ipNodes.txt`
    do
	echo $ip
        result=`sshpass -p "$password" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=$timeout $username@$ip $cmd0`
        echo $result >> result.txt
    done

#cmd1="rm -rf /root/no_ssh_cluster"
#    for ip in `cat ipMaster.txt`
#    do
#        echo $ip
#        result=`sshpass -p "$password" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=$timeout $username@$ip $cmd1`
#	echo $result >> result.txt
#    done

 pscp -l root -h ipMaster.txt -r /root/deploy-work/cpEtcdSsl/no_ssh_cluster /root

cmd2="cd /root/no_ssh_cluster && chmod a+x no_ssh_inCluster.sh && ./no_ssh_inCluster.sh"
    for ip in `cat ipMaster.txt`
    do
        echo $ip
        result=`sshpass -p "$password" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=$timeout $username@$ip $cmd2`
        echo $result >> result.txt
    done

cmd3="cd /root/no_ssh_cluster && chmod a+x scpEtcd.sh && ./scpEtcd.sh"
    for ip in `cat ipMaster.txt`
    do
        echo $ip
        result=`sshpass -p "$password" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=$timeout $username@$ip $cmd3`
	echo $result >> result.txt
    done


#    pssh -l root -h ipMaster.txt 'rm -rf /root/no_ssh_cluster'
#    pscp -l root -h ipMaster.txt -r /root/deploy-work/cpEtcdSsl/no_ssh_cluster /root
#    pssh -l root -h ipMaster.txt 'cd /root/no_ssh_cluster && chmod a+x no_ssh_inCluster.sh && ./no_ssh_inCluster.sh'
#    pssh -l root -h ipMaster.txt 'cd /root/no_ssh_cluster && chmod a+x scpEtcd.sh && ./scpEtcd.sh'

}
login
